package com.rules.admin.controller;

import com.rules.admin.utils.ResultUtils;
import com.rules.admin.login.UserHolder;
import com.rules.admin.service.RuleUserRoleService;
import com.rules.admin.utils.Constant;
import com.rules.admin.vo.RuleUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping({"/ruleUserRole"})
public class RuleUserRoleController {
   @Autowired
   private RuleUserRoleService ruleUserRoleService;
   @Autowired
   private UserHolder<RuleUser> userHolder;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> get() {
      RuleUser ruleUser = (RuleUser)this.userHolder.getUser();
      return this.ruleUserRoleService.getByUserId(ruleUser.getId()).getRoleId() == Constant.PERMISSION_ADMIN ? ResultUtils.getSuccessResultData() : ResultUtils.getFaildResultData();
   }
}
